# -*- coding:utf-8 -*-
from common.my_http import MyHttp
from common.my_baidu import MyBaidu
from common.my_time import MyTime
from common.macro_data import MacroData
from common.my_file import MyFile
from base_macro import MacroBase
import glob
import jieba
import re
import threading
import hashlib
import urllib.parse
import time
import os


'''
网络数据
'''


class BaiduZiyuanchubei(MacroBase):
    def __init__(self, file_name):
        MacroBase.__init__(self, file_name)
        pass

    def __del__(self):
        pass
        
    
    def set_param(self):
        self.set_check_title(False)
        self.set_type(305)
        self.set_max_page(6) 
        self.set_forward(10)
    
    def do_query(self, word):
        print("do_query")
        diqu = self.business.query_gdp80()
        title_check_array = [word]
        for d in diqu:
            next_page = True
            words = [d, word]
            self.get_data([d, word], [[d],[word]], ["?",";","-"])
    
    def do_query(self, words):
        print("do_query")
        diqu = self.business.query_gdp80()
        for word in words:
            for d in diqu:
                self.get_data([d, word], [[d],[word]], ["?",";","-"])

    def do_query_renkou(self):
        print("do_query")
        diqu = self.business.query_gdp80()
        for d in diqu:
            self.get_data([d, "人口"], [[d, "就业", "死亡", "减少", "增加", "增长", "普查", "贫困"],["人口"]], ["?",";","-"])


def ziyuanchubei_api():
    d = BaiduZiyuanchubei('./out/' + os.path.split(__file__)[-1].split(".")[0] + ".log")
    d.set_all_param(False, 305, 6, 10)
    d.do_query(["石油储备", "黄金储备", "外汇储备"])

    #贸易战
    d.set_all_param(False, 101, 6, 20)
    d.get_data(["中美", "贸易战"], [["中国", "美国", "中美"],["贸易战"]])

    #疫情
    d.set_all_param(False, 102, 6, 20)
    d.get_data(["新冠", "疫情"], [["新冠", "疫情"],["确诊", "疫苗", "新增", "突发", "试剂", "停运"]])
    
    #经济指标
    d.set_all_param(False, 308, 6, 10)
    d.do_query(["GDP", "CPI", "PPI", "GNP", "FDI", "通货膨胀", "通货紧缩", "第一产业", "第二产业", "第三产业", "货币存量", "贸易顺差", "贸易逆差", "价格指数", "CCI"])

    #人口
    d.set_all_param(False, 309, 6, 10)
    d.do_query_renkou()

    #财政
    d.set_all_param(False, 310, 6, 10)
    d.do_query(["财政部","财政局"])

    #国债与地方债
    d.set_all_param(False, 311, 6, 10)
    d.do_query(["国债","地方债"])

    #水利
    d.set_all_param(False, 312, 6, 10)
    d.do_query(["水利局","水利部"])
    d.get_data(["水利部"], [["水利部"]], ["?",";","-"])

    #基建
    d.set_all_param(False, 313, 6, 10)
    d.do_query(["基建"])

    #反倾销
    d.set_all_param(False, 314, 6, 10)
    d.do_query(["反倾销"])

    #数字货币
    d.set_all_param(False, 301, 6, 10)
    d.do_query(["数字货币"])
    d.get_data(["数字人民币"], [["数字人民币"]], ["?",";","-"])


    #外交关系
    d.set_all_param(False, 300, 6, 10)
    d.get_data(["俄外交部"], [["俄外交部"]], ["?",";","-"])
    d.get_data(["美外交部"], [["美外交部"]], ["?",";","-"])
    d.get_data(["英外交部"], [["英外交部"]], ["?",";","-"])


if __name__ == '__main__':
    ziyuanchubei_api()
